<?php
/**
 * Capa de abstraccion de Zend_Controller_Action
 *
 */
class MA_Controller_Action extends Zend_Controller_Action
{
    protected $_flashMessenger;
    protected $_user = false;
    protected $_config;
    protected $_adapter;
    public function init()
    {
        parent::init();
        $this->view->addHelperPath('MA/View/Helper', 'MA_View_Helper_' );
        Zend_Controller_Action_HelperBroker::addHelper(
        	new MA_Controller_Action_Helper_MAFlashMessenger());
        $this->_flashMessenger = $this->_helper->getHelper('MAFlashMessenger');
        /**
         * get config file
         */
        $this->_config = Zend_Registry::get( 'config_ini' );
        $this->_adapter = Zend_Registry::get( 'dbAdapter');

    }
    public function preDispatch()
    {
    	if( Zend_Registry::getInstance()->isRegistered( 'userApi' ) ) {
    		$this->_user = Zend_Registry::getInstance()->get( 'userApi' );
    		return ;
    	}
        $this->_user = new MA_Apis_User();
        $this->_user->init();
        Zend_Registry::getInstance()->set( 'userApi', $this->_user );
        
        
       
    	return;
//    	echo "Validacion --<br/>";
		if( $this->_user->userId != 0 ) {
			/**
			 * @todo chequear que el usuario esta dado de alta en la aplicacion
			 */
			if( ! empty( $_GET['continue'] )) {
				$this->_redirect( $_GET['continue']);
			} else {
				$this->_redirect( '/user/profile' );				
				
			}
		}
    }
    public function postDispatch()
    {
    }
}
